﻿Function.RegisterNamespace("Test.System.Web.Threading");

[Import("../../../../../Source/System.js.Web/System/Web/Threading/Thread.js")]
[Fixture]
Test.System.Web.Threading.Thread=function(){
    [Fixture]
    function Thread(){
        [Fact]
        function ThrowsIfDelegateIsOmitted(){
            var expected="System.Web.Threading.Thread.ctor: 'delegate' must be a valid Function pointer.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(null);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfDelegateIsUndefined(){
            var expected="System.Web.Threading.Thread.ctor: 'delegate' must be a valid Function pointer.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(undefined);
            });
            
            Assert.Equal(expected,actual);
        }
        
        [Fact]
        function ThrowsIfDelegateIsNull(){
            var expected="System.Web.Threading.Thread.ctor: 'delegate' must be a valid Function pointer.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(null);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfDelegateIsNotAValidFunction(){
            var expected="System.Web.Threading.Thread.ctor: 'delegate' must be a valid Function pointer.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread({});
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsOmitted(){
            var expected="System.Web.Threading.Thread.ctor: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(function(){});
            });
            
            Assert.Equal(expected,actual);
        }        

        [Fact]
        function ThrowsIfIntervalIsUndefined(){
            var expected="System.Web.Threading.Thread.ctor: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(function(){},undefined);
            });
            
            Assert.Equal(expected,actual);
        }        

        [Fact]
        function ThrowsIfIntervalIsNull(){
            var expected="System.Web.Threading.Thread.ctor: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(function(){},null);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsBooleanTrue(){
            var expected="System.Web.Threading.Thread.ctor: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(function(){},true);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsBooleanFalse(){
            var expected="System.Web.Threading.Thread.ctor: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(function(){},false);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsArray(){
            var expected="System.Web.Threading.Thread.ctor: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(function(){},[]);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsDate(){
            var expected="System.Web.Threading.Thread.ctor: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(function(){},new Date());
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsError(){
            var expected="System.Web.Threading.Thread.ctor: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(function(){},new Error());
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsFunction(){
            var expected="System.Web.Threading.Thread.ctor: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(function(){},function(){});
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsObject(){
            var expected="System.Web.Threading.Thread.ctor: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(function(){},{});
            });
            
            Assert.Equal(expected,actual);
        }
        
        [Fact]
        function ThrowsIfIntervalIsNotAWholeNumber(){
            var expected="System.Web.Threading.Thread.ctor: 'interval' must be a whole Number.";

            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(function(){},1.5);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsLessThanZero(){
            var expected="System.Web.Threading.Thread.ctor: 'interval' must be a Number greater than or equal to zero (0).";
            
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(function(){},-1);
            });
            
            Assert.Equal(expected,actual);
        }
        
        [Fact]
        function DoesNotThrowIfDelegateAndIntervalAreValid(){
            var actual=Record.Exception(function(){
                new System.Web.Threading.Thread(function(){},1);
            });
            
            Assert.Null(actual);
        }
    }        
    
    [Fixture]
    function Dispose(){
        [Fact]
        function CallsClearTimeout(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var actual=false;
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){return "timer";},clearTimeout:function(){actual=true;}});

            mockTimers(function(){
                target.Start();
                target.Dispose();
            });
            
            Assert.True(actual);
        }

        [Fact]
        function SetsThreadStateToDisposed(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected="Disposed";
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});
            
            mockTimers(function(){
                target.Dispose();
            });
            var actual=target.ThreadState;
            
            Assert.Equal(expected,actual);
        }
        
        [Fact]
        function ReleasesHandleToDelegate(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});
            
            mockTimers(function(){
                target.Dispose();
            });
            var actual=target.GetDelegate();
            
            Assert.Null(actual);
        }
    }
    
    [Fixture]
    function GetDelegate(){
        [Fact]
        function ReturnsDelegatePassedToConstructor(){
            var expected=function(){/*expected*/};
            var target=new System.Web.Threading.Thread(expected,1);
        
            var actual=target.GetDelegate();
        
            Assert.Same(expected,actual);
        }
    }

    [Fixture]
    function GetInterval(){
        [Fact]
        function ReturnsIntervalPassedToConstructor(){
            var expected=42;
            var target=new System.Web.Threading.Thread(function(){},expected);
        
            var actual=target.GetInterval();
        
            Assert.Same(expected,actual);
        }
    }
    
    [Fixture]
    function Resume(){
        [Fact]
        function ThrowsIfThreadIsInitialized(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected=String.Format("System.Web.Threading.Thread.Resume: 'Resume' is not a valid operation for the state '{0}'.",target.ThreadState);
        
            var actual=Record.Exception(function(){
                target.Resume();
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfThreadIsRunning(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected=String.Format("System.Web.Threading.Thread.Resume: 'Resume' is not a valid operation for the state '{0}'.",System.Web.Threading.ThreadState.Running);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){return "timer";},clearTimeout:function(){}});        
            var actual=null;

            mockTimers(function(){
                actual=Record.Exception(function(){
                    target.Start();
                    target.Resume();
                });
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfThreadIsDisposed(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected=String.Format("System.Web.Threading.Thread.Resume: 'Resume' is not a valid operation for the state '{0}'.",System.Web.Threading.ThreadState.Disposed);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){return "timer";},clearTimeout:function(){}});        
            var actual=null;

            mockTimers(function(){
                actual=Record.Exception(function(){
                    target.Dispose();
                    target.Resume();
                });
            });

            Assert.Equal(expected,actual);
        }

        [Fact]
        function DoesNotThrowIfThreadIsSuspended(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){return "timer";},clearTimeout:function(){}});        
            var actual=null;

            mockTimers(function(){
                actual=Record.Exception(function(){
                    target.Start();
                    target.Suspend();
                    target.Resume();
                });
            });

            Assert.Null(actual);
        }

        [Fact]
        function SetsThreadStateToRunning(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){return "timer";},clearTimeout:function(){}});        
            var expected=System.Web.Threading.ThreadState.Running;
            var actual=null;

            mockTimers(function(){
                target.Start();
                target.Suspend();
                target.Resume();
                actual=target.ThreadState;
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function CallsWindowSetTimeout(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){actual=true;},clearTimeout:function(){}});        
            var actual=false;

            mockTimers(function(){
                target.Start();
                target.Suspend();
                actual=false;
                target.Resume();
            });
            
            Assert.True(actual);
        }

        [Fact]
        function PassesIntervalToSetTimeout(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected=target.GetInterval();
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(delegate,interval){actual=interval;},clearTimeout:function(){}});        
            var actual=null;

            mockTimers(function(){
                target.Start();
                target.Suspend();
                actual=null;
                target.Resume();
            });
                        
            Assert.Equal(expected,actual);
        }

        [Fact]
        function PassesOneMillisecondToSetTimeoutToBreakThreadIfImmediateIsTrue(){
            var target=new System.Web.Threading.Thread(function(){},1000);
            var expected=1;
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(delegate,interval){actual=interval;},clearTimeout:function(){}});        
            var actual=null;

            mockTimers(function(){
                target.Start();
                target.Suspend();
                actual=null;
                target.Resume(true);
            });
                        
            Assert.Equal(expected,actual);
        }
    }
    
    [Fixture]
    function SetInterval(){
        [Fact]
        function ThrowsIfIntervalIsOmitted(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected="System.Web.Threading.Thread.SetInterval: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                target.SetInterval();
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsUndefined(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected="System.Web.Threading.Thread.SetInterval: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                target.SetInterval(undefined);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsNull(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected="System.Web.Threading.Thread.SetInterval: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                target.SetInterval(null);
            });
            
            Assert.Equal(expected,actual);
        }
        
        [Fact]
        function ThrowsIfIntervalIsBooleanTrue(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected="System.Web.Threading.Thread.SetInterval: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                target.SetInterval(true);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsBooleanFalse(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected="System.Web.Threading.Thread.SetInterval: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                target.SetInterval(false);
            });
            
            Assert.Equal(expected,actual);
        }
        
        [Fact]
        function ThrowsIfIntervalIsArray(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected="System.Web.Threading.Thread.SetInterval: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                target.SetInterval([]);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsError(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected="System.Web.Threading.Thread.SetInterval: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                target.SetInterval(new Error());
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsDate(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected="System.Web.Threading.Thread.SetInterval: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                target.SetInterval(new Date());
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsObject(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected="System.Web.Threading.Thread.SetInterval: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                target.SetInterval({});
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsFunction(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected="System.Web.Threading.Thread.SetInterval: 'interval' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                target.SetInterval(function(){});
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsNotAWholeNumber(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected="System.Web.Threading.Thread.SetInterval: 'interval' must be a whole Number.";

            var actual=Record.Exception(function(){
                target.SetInterval(1.5);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfIntervalIsLessThanZero(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected="System.Web.Threading.Thread.SetInterval: 'interval' must be a Number greater than or equal to zero (0).";
            
            var actual=Record.Exception(function(){
                target.SetInterval(-1);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function DoesNotThrowIfIntervalIsValid(){
            var target=new System.Web.Threading.Thread(function(){},1);
            
            var actual=Record.Exception(function(){
                target.SetInterval(1);
            });
            
            Assert.Null(actual);
        }

        [Fact]
        function SetsInterval(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected=42;

            target.SetInterval(expected);
            var actual=target.GetInterval(expected);
            
            Assert.Equal(expected,actual);
        }
    }
    
    [Fixture]
    function Start(){
        [Fact]
        function ThrowsIfStateIsDisposed(){
            var target=new System.Web.Threading.Thread(function(){},1);
            target.Dispose();
            var expected=String.Format("System.Web.Threading.Thread.Start: 'Start' is not a valid operation for the state '{0}'.",target.ThreadState);
    
            var actual=Record.Exception(function(){    
                target.Start();
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfStateIsRunning(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});        
            var expected=String.Format("System.Web.Threading.Thread.Start: 'Start' is not a valid operation for the state '{0}'.",System.Web.Threading.ThreadState.Running);
            var actual=null;
            
            mockTimers(function(){
                actual=Record.Exception(function(){    
                    target.Start();
                    target.Start();
                });
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfStateIsSuspended(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});        
            var expected=String.Format("System.Web.Threading.Thread.Start: 'Start' is not a valid operation for the state '{0}'.",System.Web.Threading.ThreadState.Suspended);
            var actual=null;
            
            mockTimers(function(){
                actual=Record.Exception(function(){    
                    target.Start();
                    target.Suspend();
                    target.Start();
                });
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function SetsStateToRunning(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});        
            var expected=System.Web.Threading.ThreadState.Running;
            var actual=null;
            
            mockTimers(function(){
                target.Start();
                actual=target.ThreadState;
            });
            
            Assert.Equal(expected,actual);
        }
    
        [Fact]
        function CallsDelegateWithNoParameters(){
            var target=new System.Web.Threading.Thread(function(){
                actual=true;
            },1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});        
            var actual=false;
            
            mockTimers(function(){
                target.Start();
            });
            
            Assert.True(actual);
        }

        [Fact]
        function PassesThreadContextToDelegate(){
            var target=new System.Web.Threading.Thread(function(targetContext){
                actual=targetContext;
            },1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});        
            var expected={
                Cancel:false,
                Instance:target,
                Interval:target.GetInterval()
            };
            var actual=null;
            
            mockTimers(function(){
                target.Start();
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function CallsDelegateWithParameters(){
            var target=new System.Web.Threading.Thread(function(){
                actual=true;
            },1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});        
            var actual=false;
            
            mockTimers(function(){
                target.Start({});
            });
            
            Assert.True(actual);
        }

        [Fact]
        function PassesParameterToDelegate(){
            var target=new System.Web.Threading.Thread(function(targetContext,targetParameter){
                actual=targetParameter;
            },1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});        
            var expected={};
            var actual=null;
            
            mockTimers(function(){
                target.Start(expected);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function PassesParametersToDelegate(){
            var target=new System.Web.Threading.Thread(function(targetContext,targetParameterOne,targetParameterTwo){
                actual=targetParameterTwo;
            },1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});        
            var expected={id:2};
            var actual=null;
            
            mockTimers(function(){
                target.Start({id:1},expected);
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function SettingCancelOnThreadContextSetsThreadStateToSuspended(){
            var target=new System.Web.Threading.Thread(function(targetContext){
                targetContext.Cancel=true;
            },1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});        
            var expected="Suspended";
            var actual=null;
            
            mockTimers(function(){
                target.Start();
                actual=target.ThreadState;
            });
            
            Assert.Equal(expected,actual);
        }
        
        [Fact]
        function ChangingIntervalOnThreadContextSetsThreadInterval(){
            var target=new System.Web.Threading.Thread(function(targetContext){
                targetContext.Interval=expected;
            },1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});        
            var expected=9001;
            var actual=null;
            
            mockTimers(function(){
                target.Start();
                actual=target.GetInterval();
            });
            
            Assert.Equal(expected,actual);
        }
        
        [Fact]
        function QueuesUpNextStepThroughSetTimeout(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){actual=true},clearTimeout:function(){}});        
            var actual=false;
            
            mockTimers(function(){
                target.Start();
            });
            
            Assert.True(actual);
        }

        [Fact]
        function DoesNotQueueUpNextStepIfCancelIsSetOnThreadContext(){
            var target=new System.Web.Threading.Thread(function(threadContext){
                threadContext.Cancel=true;
            },1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){actual=true},clearTimeout:function(){}});        
            var actual=false;
            
            mockTimers(function(){
                target.Start();
            });
            
            Assert.False(actual);
        }
    }
    
    [Fixture]
    function Suspend(){
        [Fact]
        function ThrowsIfThreadIsInitialized(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var expected=String.Format("System.Web.Threading.Thread.Suspend: 'Suspend' is not a valid operation for the state '{0}'.",target.ThreadState);        
        
            var actual=Record.Exception(function(){
                target.Suspend();
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfThreadIsDisposed(){
            var target=new System.Web.Threading.Thread(function(){},1);
            target.Dispose();
            var expected=String.Format("System.Web.Threading.Thread.Suspend: 'Suspend' is not a valid operation for the state '{0}'.",target.ThreadState);        
        
            var actual=Record.Exception(function(){
                target.Suspend();
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfThreadIsSuspended(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});        
            var expected=String.Format("System.Web.Threading.Thread.Suspend: 'Suspend' is not a valid operation for the state '{0}'.",System.Web.Threading.ThreadState.Suspended);                
            var actual=null;
            
            mockTimers(function(){
                actual=Record.Exception(function(){
                    target.Start();
                    target.Suspend();
                    target.Suspend();
                });
            });
                
            Assert.Equal(expected,actual);
        }

        [Fact]
        function DoesNotThrowIfThreadIsRunning(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});        
            var actual=null;
            
            mockTimers(function(){
                actual=Record.Exception(function(){
                    target.Start();
                    target.Suspend();
                });
            });

            Assert.Null(actual);
        }
        
        [Fact]
        function SetsStateToSuspended(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){},clearTimeout:function(){}});        
            var expected=System.Web.Threading.ThreadState.Suspended;
        
            mockTimers(function(){
                target.Start();
                target.Suspend();
            });
            var actual=target.ThreadState;
        
            Assert.Equal(expected,actual);
        }
        
        [Fact]
        function CallsWindowClearTimeout(){
            var target=new System.Web.Threading.Thread(function(){},1);
            var mockTimers=Mocks.GetMocks(Object.Global(),{setTimeout:function(){return "timer";},clearTimeout:function(){actual=true;}});
            var actual=false;
        
            mockTimers(function(){
                target.Start();
                actual=false;
                target.Suspend();
            });
        
            Assert.True(actual);
        }

    }

}
